﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace WinDataInspector.Converters
{
    [ValueConversion(typeof(byte), typeof(byte))]
    class ByteConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string input = (string)value;

            byte output = 0;

            bool result = Byte.TryParse(input, System.Globalization.NumberStyles.HexNumber, null, out output);

            if (!result)
            {
                value = "00";
            }

            return value;
        }
    }
}
